package com.betterjr.modules.application;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.dubbo.config.annotation.Reference;
import com.betterjr.common.web.ControllerExceptionHandler;
import com.betterjr.common.web.ControllerExceptionHandler.ExceptionHandler;
import com.betterjr.common.web.Servlets;

@Controller
@RequestMapping(value = "/Platform/ApplicationOperorg")
public class ApplicationOperorgController {

    private static final Logger logger = LoggerFactory.getLogger(ApplicationOperorgController.class);

    @Reference(interfaceClass = IApplicationOperorgService.class)
    private IApplicationOperorgService operorgService;

    /**
     * 
     * @Title: saveAssignedApplicationToCust 
     * @Description: 分配应用给企业
     * @param request
     * @param custNo  企业编号
     * @param businStatus  状态 1未生效 2已生效 9已失效
     * @param applicationIds 应用ids
     * @return 应用机构表集合
     * @throws 
     * @author xuyp
     * @date 2017年11月25日 下午1:45:28
     */
    @RequestMapping(value = "/saveAssignedApplicationToCust", method = RequestMethod.POST)
    public @ResponseBody String saveAssignedApplicationToCust(final HttpServletRequest request, Long custNo,
            String businStatus, String applicationIds) {
        final Map<String, Object> anMap = Servlets.getParametersStartingWith(request, "");
        logger.info("入参：" + anMap);
        return ControllerExceptionHandler.exec(new ExceptionHandler() {
            @Override
            public String handle() {
                return operorgService.webSaveAssignedApplicationToCust(applicationIds, custNo, businStatus);
            }
        }, "操作失败", logger);
    }

    /**
     * 
     * @Title: queryApplication 
     * @Description: 查询当前企业应用的列表 
     * @param request
     * @param applicationTypeId  类型id
     * @param applicationGroupId 分组id
     * @param businStatus 状态  状态 1未生效 2已生效 9已失效
     * @return 应用列表
     * @throws 
     * @author xuyp
     * @date 2017年11月25日 下午1:48:49
     */
    @RequestMapping(value = "/queryApplication", method = RequestMethod.POST)
    public @ResponseBody String queryApplication(final HttpServletRequest request, Long applicationTypeId,
            Long applicationGroupId, String businStatus) {
        final Map<String, Object> anMap = Servlets.getParametersStartingWith(request, "");
        logger.info("入参：" + anMap);
        return ControllerExceptionHandler.exec(new ExceptionHandler() {
            @Override
            public String handle() {
                return operorgService.webQueryApplication(applicationTypeId, applicationGroupId, businStatus);
            }
        }, "操作失败", logger);
    }

}
